package com.shupian.controller;

import com.shupian.domain.ResponseResult;
import com.shupian.domain.dto.AddArticleDto;
import com.shupian.domain.entity.Menu;
import com.shupian.enums.AppHttpCodeEnum;
import com.shupian.service.ArticleService;

import com.shupian.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

@RestController
@RequestMapping("/content/article")
@Validated
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @Autowired
    private MenuService menuService;

    @PostMapping
    public ResponseResult addArticle(@RequestBody  AddArticleDto addArticleDto){
        return articleService.addArticle(addArticleDto);
    }


    //获取文章列表
    @GetMapping("/list")
    public ResponseResult list(@Min(1) Integer pageNum,@Min(1) Integer pageSize, String title, String summary){

        return articleService.getList(pageNum,pageSize,title,summary);
    }

    /**
     * 修改文章
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleById(@PathVariable("id") @Min(1) Integer id){
        return articleService.getArticleById(id);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@Min(1)@PathVariable("id")  Integer id){
        return articleService.deleteById(id);
    }





}


